<template>
  <div class="basicinformation_add">
    <el-main>
      <div>
        <div class="title">
          <span>账号信息</span>
        </div>
        <div style="margin-top: 20px; display: flex; margin-bottom: 20px">
          <div
            style="
              text-align: right;
              width: 100px;
              margin-top: 7px;
              margin-right: 10px;
            "
          >
            绑定发货员账号
          </div>
          <div style="width: 300px">
            <el-select v-model="supplierOne.sysId" placeholder="请选择发货员账号">
              <el-option
                v-for="item in users"
                :key="item.id"
                :label="item.username"
                :value="item.id"
              />
            </el-select>
          </div>
          <div
            style="
              text-align: right;
              width: 100px;
              margin-top: 7px;
              margin-right: 10px;
            "
          >
            绑定财务账号
          </div>
          <div style="width: 300px">
            <el-select v-model="supplierOne.supplierBusinessUserId" placeholder="请选择财务账号">
              <el-option
                v-for="item in financeAccount"
                :key="item.id"
                :label="item.username"
                :value="item.id"
              />
            </el-select>
          </div>
        </div>
        <div style="display: none; margin-top: 20px; margin-bottom: 20px">
          <div style="text-align: right; margin-top: 7px; margin-right: 10px">
            密码
          </div>
          <div style="width: 300px">
            <!-- <el-input :disabled="true" v-model="sys_id"></el-input> -->
          </div>
        </div>
      </div>

      <div style="margin-top: 10px; margin-left: 110px">
        <el-button type="primary" plain @click="funcback">确定</el-button>
        <el-button  type="primary" plain @click="goBack">
          取消
        </el-button>
      </div>
    </el-main>
  </div>
</template>

<script>
import { handleActivePath } from '@/utils/routes'
import { mapActions } from 'vuex'
import {
  bindsysuser,
  listsysusersss,
  getsupplierinfo,
  bindingFinanceAccount,
} from '@/api/purchase/supplierapi'
export default {
  data() {
    return {
      id: null,
      supplierOne: {
        sysId:'',
        id:this.$route.params.id,
        supplierBusinessUserId:''
      }, //供应商数据
      users: [], //用户列表
      financeAccount: [], //财务列表
    }
  },
  async mounted() {
    let data = {
      id: this.$route.params.id,
    }
    let data2 = {
      purchaseSupplierId: this.$route.params.id,
    }
    this.id = data.id
    let res = await listsysusersss(data2)
    this.users = res.data
    let financeList = await bindingFinanceAccount(data2)
    this.financeAccount = financeList.data
    let res2 = await getsupplierinfo(data)
    this.supplierOne.sysId = res2.data.sysId
    this.supplierOne.supplierBusinessUserId = res2.data.supplierBusinessUserId
  },
  methods: {
    goBack() {
      this.$router.push('/purchase/initialvalue_supplier')
    },
    funcback() {
      this.$confirm('确定绑定该系统用户?', '确定', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(async () => {
          let res = await bindsysuser(this.supplierOne)
          if (res.status == 200) {
            this.$message.success('绑定成功')
            this.goBack()
          } else {
            this.$message.error('绑定失败')
          }
        })
        .catch(() => {})
    },
  },
}
</script>

<style>
.basicinformation_add .title {
  padding-bottom: 10px;
  border-bottom: 1px solid #eee;
}

.basicinformation_add .title span {
  display: inline-block;
  padding-left: 8px;
  font-size: 16px;
  border-left: 4px solid #1890ff;
}

.basicinformation_add .title p {
  display: inline;
}
</style>
